package com.study.talk.adapter;

import android.annotation.SuppressLint;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.study.talk.R;

import java.util.List;

public class MomentGridViewAdapter extends BaseAdapter {
    List<Uri> imageUriList;
    private ImageView momentGridViewItemImage;

    public MomentGridViewAdapter(List<Uri> imageUriList) {
        this.imageUriList = imageUriList;
    }

    @Override
    public int getCount() {
        return imageUriList.size();
    }

    @Override
    public Object getItem(int position) {
        return imageUriList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        @SuppressLint("ViewHolder") View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.moment_grid_view_item, null);
        initView(view);
        Glide.with(parent.getContext()).load(imageUriList.get(position)).into(momentGridViewItemImage);
        return view;
    }

    private void initView(View view) {
        momentGridViewItemImage = (ImageView) view.findViewById(R.id.moment_grid_view_item_image);
    }
}
